package com.zhu.storesmanager;

import java.util.List;

import com.zhu.storesmanager.models.BrandsDataItem;
import com.zhu.storesmanager.models.ProjectDataItem;
import com.zhu.storesmanager.models.SpecialTaskItem;
import com.zhu.storesmanager.models.SyncModel;
import com.zhu.storesmanager.models.VisitTaskInfo;
import com.zhu.storesmanager.provider.StoresManagerSettings;
import com.zhu.storesmanager.utils.Actions;
import com.zhu.storesmanager.utils.DataUtils;
import com.zhu.storesmanager.utils.DatabaseUtil;
import com.zhu.storesmanager.utils.Log;
import com.zhu.storesmanager.utils.ViewsUtil;
import com.zhu.storesmanager.views.PopEditText;
import com.zhu.storesmanager.views.PopMenu;

import android.app.Activity;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.RadioGroup;
import android.widget.TextView;


/**
 * POSM布置反馈
 */
public class SvStorePOSMActivity extends Activity implements OnClickListener{

	//异步查询数据库token
	private final static int POSM_DATA_QUERY_TOKEN = 0; //查询POSM数据
	private final static int PROJECT_DATA_QUERY_TOKEN = 1; //拜访文本数据
	private DataQueryHandler mDataQueryHandler = null; //数据异步查询Handler

	private RadioGroup mPCornerRadioGroup = null; //样机角贴
	private RadioGroup mPosterRadioGroup = null; //海报及吊旗
	private RadioGroup mSinglepageRadioGroup = null; //单页
	private RadioGroup mIstandRadioGroup = null; //X展架及堆头
	private TextView mErrorInfoView = null; //异常信息
	private TextView mBackup1Title = null; //备份标题1
	private TextView mBackup2Title = null; //备份标题2
	private TextView mBackup1View = null; //备份1
	private TextView mBackup2View = null; //备份2
	private PopEditText mPopEditText = null; //反馈输入框
	private long mDBid = -1; //数据库保存数据ID
    private VisitTaskInfo mVisitTaskInfo = null; //拜访门店数据
    private PopMenu mPopMenu = null; //弹出菜单
    private boolean isDataChange = true; //数据是否发生变化
    private List<ProjectDataItem> mProjectList = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Parcelable parcelable = getIntent().getParcelableExtra("info");
        mVisitTaskInfo = (VisitTaskInfo) parcelable;
		setContentView(R.layout.activity_sv_storesposm);

		setupViews();
		initData();
	}

	/**
	 * 初始换界面
	 */
	private void setupViews(){
		((TextView) findViewById(R.id.title_text)).setText(R.string.store_posm); //TITLE
		findViewById(R.id.svbottom_menu_back).setOnClickListener(this);
	    findViewById(R.id.svbottom_menu_save).setOnClickListener(this);
	    findViewById(R.id.svbottom_menu_menu).setOnClickListener(this);
	    mErrorInfoView = (TextView)findViewById(R.id.svstoreposm_errorinfo);
	    mErrorInfoView.setOnClickListener(this);
	    mBackup1View = (TextView)findViewById(R.id.svstoreposm_backup1);
	    mBackup1View.setOnClickListener(this);
	    mBackup2View = (TextView)findViewById(R.id.svstoreposm_backup2);
	    mBackup2View.setOnClickListener(this);
	    mBackup1Title = (TextView)findViewById(R.id.posm_backup1_title);
	    mBackup2Title = (TextView)findViewById(R.id.posm_backup2_title);

	    mPCornerRadioGroup = setViewData(R.id.svstoreposm_pcorner, R.string.posm_prototypecorner);
		mPosterRadioGroup = setViewData(R.id.svstoreposm_poster, R.string.posm_poster);
		mSinglepageRadioGroup = setViewData(R.id.svstoreposm_singlepage, R.string.posm_singlepage);
		mIstandRadioGroup = setViewData(R.id.svstoreposm_istand, R.string.posm_istand);

		mPopEditText = new PopEditText((FrameLayout)findViewById(R.id.layout));
		mPopMenu = new PopMenu(this, findViewById(R.id.bottom_menu), PopMenu.MENU_POSM);
	    mPopMenu.setVisitTaskInfo(mVisitTaskInfo);
	}

	/**
     * 初始化数据
     */
    private void initData(){
    	if(!DataUtils.mUserData.isAdmin()){ //检测非管理员
    		if(mDataQueryHandler == null){
        		mDataQueryHandler = new DataQueryHandler(getContentResolver());
        	}
        	startQueryProjects();
    	}else{
        	setDataFromAdminSearchData();
    	}
    }

    /**
     * 查询project数据
     */
    private void startQueryProjects(){
    	String where = StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE + "=" + StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM
    	+ " OR " + StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE + "=" + StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP;
    	mDataQueryHandler.startQuery(PROJECT_DATA_QUERY_TOKEN, null, 
				StoresManagerSettings.DataProjectsColumns.CONTENT_URI_NO_NOTIFICATION,
				null, where, null, null);
    }

    /**
     * 查询保存数据
     */
    private void startQueryDatas(){
    	String where = StoresManagerSettings.SupervisorStorePOSMColumns.STOREID + "=\'" + mVisitTaskInfo.mStoreId+ "\'";
    	mDataQueryHandler.startQuery(POSM_DATA_QUERY_TOKEN, null, 
				StoresManagerSettings.SupervisorStorePOSMColumns.CONTENT_URI_NO_NOTIFICATION,
				null, where, null, null);
    }

	/**
	 * 设置界面数据
	 * @return radioGroup
	 * @param parentId 父ID
	 * @param textId 文本id
	 */
	private RadioGroup setViewData(int parentId, int textId){
		View view = findViewById(parentId);
		RadioGroup radioGroup = (RadioGroup)view.findViewById(R.id.radiogroup);
		((TextView)view.findViewById(R.id.radiogroup_label)).setText(textId);
		return radioGroup;
	}

	/**
	 * 设置界面数据
	 * @param parentId 父ID
	 * @param text 文本
	 */
	private void setViewDataText(int parentId, String text){
		View view = findViewById(parentId);
		((TextView)view.findViewById(R.id.radiogroup_label)).setText(text);
	}


	/*
	 * (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		 if(v != null){
	            switch(v.getId()){
	                case R.id.svbottom_menu_back://返回
	                	if(!doBack()){
	                         finish();
	                     }
	                    break;
	                case R.id.svbottom_menu_save: //保存
	                	saveData();
	                    break;
	                case R.id.svstoreposm_errorinfo: //异常详情
	                	mPopEditText.showPopEditText(R.string.posm_errorinfo, (TextView)v);
	                	break;
	                case R.id.svstoreposm_backup1: //备份1
	                	mPopEditText.showPopEditText(R.string.posm_backup1, (TextView)v);
	                	break;
	                case R.id.svstoreposm_backup2: //备份2
	                	mPopEditText.showPopEditText(R.string.posm_backup2, (TextView)v);
	                	break;
	                case R.id.svbottom_menu_menu: //菜单
	                	mPopMenu.showMenu();
	                	break;
	            }
	        }
	}

	/**
     * 按键事件处理
     */
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            if(!doBack()){
                finish();
            }
            return true;
        }
        return false;
    }

    /**
     * 返回事件处理
     */
    private boolean doBack(){
        if(mPopEditText != null && mPopEditText.doBack()){
            return true;
        }
        if(isDataChange){
        	if(DataUtils.mUserData.isAdmin()){
        		return false;
        	}
            popExitDialog();
            return true;
        }
        return false;
    }

    /**
     * 保存数据
     */
    private void saveData(){
    	int iPCorner = getCheckedRadioButtonIndex(mPCornerRadioGroup); //获取样机角贴选中项
    	int iPoster = getCheckedRadioButtonIndex(mPosterRadioGroup); //获取海报及吊旗选中项
    	int iSinglePage = getCheckedRadioButtonIndex(mSinglepageRadioGroup); //获取单页选中项
    	int iIstand = getCheckedRadioButtonIndex(mIstandRadioGroup); //获取X展架及堆头选中项
    	if(checkSelectIndex(iPCorner) && checkSelectIndex(iPoster)
    			&& checkSelectIndex(iSinglePage) && checkSelectIndex(iIstand)){ //检测数据
    		
    	}else{
           String error = mErrorInfoView.getText().toString().trim();
           if(error == null || error.length() == 0){//没有填写数据
        	   Actions.toastShort(this, R.string.psom_notnull);
        	   return;
           }
    	}
    	ContentValues values = new ContentValues();
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_PCORNER, iPCorner);
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_POSTER, iPoster);
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_SINGLEPAGE, iSinglePage);
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_STAND, iIstand);
    	values.put(StoresManagerSettings.SAVED, 0);
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_ERRORINFO, mErrorInfoView.getText().toString());
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_BACKUPTEXT1, mBackup1Title.getText().toString());
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_BACKUPTEXT2, mBackup2Title.getText().toString());
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_BACKUP1, mBackup1View.getText().toString());
    	values.put(StoresManagerSettings.SupervisorStorePOSMColumns.POSM_BACKUP2, mBackup2View.getText().toString());
    	if(Actions.checkRadioButtonData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 1), iPCorner)
    			&& Actions.checkRadioButtonData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 2), iPoster)
    			&& Actions.checkRadioButtonData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 3), iSinglePage)
    			&& Actions.checkRadioButtonData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 4), iIstand)
    			&& !Actions.isNull(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP, 1), mBackup1View.getText().toString())
    			&& !Actions.isNull(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP, 2), mBackup2View.getText().toString())){
    		DatabaseUtil.saveVisitStatus(this, DatabaseUtil.TYPE_POSM , Integer.parseInt(mVisitTaskInfo.mVisitId), 1);
    	}else{
    		DatabaseUtil.saveVisitStatus(this, DatabaseUtil.TYPE_POSM , Integer.parseInt(mVisitTaskInfo.mVisitId), 0);
    	}
    	if(mDBid == -1){ //如果不存在数据 则插入新数据
			values.put(StoresManagerSettings.SupervisorStorePOSMColumns.STOREID, mVisitTaskInfo.mStoreId);
			Uri uri = getContentResolver().insert(StoresManagerSettings.SupervisorStorePOSMColumns.CONTENT_URI_NO_NOTIFICATION, values);
			mDBid = Long.parseLong(uri.getPathSegments().get(1));
		}else{ //存在则更新历史数据
			getContentResolver().update(StoresManagerSettings.SupervisorStorePOSMColumns.getContentUri(mDBid, false), values, null, null);
		}
		Actions.toastShort(this, this.getString(R.string.datasave_success));
    }

    /**
     * 检测数据是否是齐或者不允许或者不填写
     * @param selectIndex 选中项
     * @return true
     */
    private boolean checkSelectIndex(int selectIndex){
    	if(selectIndex == 0 || selectIndex == 3 || selectIndex == -1){
    		return true;
    	}
    	return false;
    }

    /**
     *获取选中项的索引 
     *@param radioGroup 选项组
     *@param index 选中索引 -1为未选中
     */
    private int getCheckedRadioButtonIndex(RadioGroup radioGroup){
    	int index = radioGroup.getCheckedRadioButtonId();
    	if(index != -1){
    		index = radioGroup.indexOfChild(radioGroup.findViewById(index));
    	}
    	return index;
    }

    /**
     * 更新数据从数据库保存的数据
     * @param cursor 数据
     */
    private void updateDataFromCursor(Cursor cursor){
    	if(cursor != null && cursor.moveToFirst() && cursor.getCount() > 0){
    		boolean isSaved = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SAVED)) == 1 ? true : false;
    		int iPCorner = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStorePOSMColumns.POSM_PCORNER));
    		int iPoster = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStorePOSMColumns.POSM_POSTER));
    		int iSinglePage = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStorePOSMColumns.POSM_SINGLEPAGE));
    		int iIstand = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStorePOSMColumns.POSM_STAND));

    		String errorinfo = cursor.getString(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStorePOSMColumns.POSM_ERRORINFO));
    		String back1 = cursor.getString(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStorePOSMColumns.POSM_BACKUP1));
    		String back2 = cursor.getString(cursor.getColumnIndexOrThrow(
                    StoresManagerSettings.SupervisorStorePOSMColumns.POSM_BACKUP2));

    		mDBid = cursor.getLong(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreSampleColumns._ID));

    		iPCorner = DataUtils.updateIntDataFromHistoryData(mProjectList, iPCorner, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 1);
    		if(iPCorner != -1){
    		    mPCornerRadioGroup.check(mPCornerRadioGroup.getChildAt(iPCorner).getId());    
            }
    		iPoster = DataUtils.updateIntDataFromHistoryData(mProjectList, iPoster, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 2);
    		if(iPoster != -1){
    		    mPosterRadioGroup.check(mPosterRadioGroup.getChildAt(iPoster).getId());    
            }
    		iSinglePage = DataUtils.updateIntDataFromHistoryData(mProjectList, iSinglePage, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 3);
    		if(iSinglePage != -1){
    		    mSinglepageRadioGroup.check(mSinglepageRadioGroup.getChildAt(iSinglePage).getId());    
            }
    		iIstand = DataUtils.updateIntDataFromHistoryData(mProjectList, iIstand, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 4);
    		if(iIstand != -1){
    		    mIstandRadioGroup.check(mIstandRadioGroup.getChildAt(iIstand).getId());    
            }
    		mErrorInfoView.setText(DataUtils.updateStringDataFromHistoryData(mProjectList, errorinfo, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM, 5));
    		mBackup1View.setText(DataUtils.updateStringDataFromHistoryData(mProjectList, back1, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP, 1));
    		mBackup2View.setText(DataUtils.updateStringDataFromHistoryData(mProjectList, back2, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP, 2));
    	}
    	if(cursor != null){
    		cursor.close();
    		cursor = null;
    	}
    }

    /**
  	 * 异步数据查询
  	 */
  	private final class DataQueryHandler extends AsyncQueryHandler {
          public DataQueryHandler(ContentResolver contentResolver) {
              super(contentResolver);
          }

          /**
           * 查询结果返回
           * (non-Javadoc)
           * @see android.content.AsyncQueryHandler#onQueryComplete(int, java.lang.Object, android.database.Cursor)
           */
          @Override
          protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
              switch (token) {
                  case POSM_DATA_QUERY_TOKEN:
                  		updateDataFromCursor(cursor);
                      break;
                  case PROJECT_DATA_QUERY_TOKEN:
                  	   updateProjectDataFromCursor(cursor);
                      break;
                  default:
                      Log.e("onQueryComplete called with unknown token " + token);
              }
          }

          @Override
          protected void onDeleteComplete(int token, Object cookie, int result) {

          }
      }

    /**
	 * 更新project数据从数据库
	 * @param cursor 数据库数据
	 */
	private void updateProjectDataFromCursor(Cursor cursor){
		mProjectList = DatabaseUtil.getProjectDataList(cursor);
		if(mProjectList != null && mProjectList.size() > 0){
			for(ProjectDataItem item : mProjectList){
				updateViewFromProject(item);
			}
		}
		startQueryDatas();
	}

    /**
	 * 从project数据更新界面
	 */
	private void updateViewFromProject(ProjectDataItem item) {
		if(item.mType == StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM){
			if (item.mId == 1) {
				if (item.isShow) {
					setViewDataText(R.id.svstoreposm_pcorner, item.mName);
				} else {
					findViewById(R.id.svstoreposm_pcorner).setVisibility(View.GONE);
				}
			} else if (item.mId == 2) {
				if (item.isShow) {
					setViewDataText(R.id.svstoreposm_poster, item.mName);
				} else {
					findViewById(R.id.svstoreposm_poster).setVisibility(View.GONE);
				}
			} else if (item.mId == 3) {
				if (item.isShow) {
					setViewDataText(R.id.svstoreposm_singlepage, item.mName);
				} else {
					findViewById(R.id.svstoreposm_singlepage).setVisibility(View.GONE);
				}
			} else if (item.mId == 4) {
				if (item.isShow) {
					setViewDataText(R.id.svstoreposm_istand, item.mName);
				} else {
					findViewById(R.id.svstoreposm_istand).setVisibility(View.GONE);
				}
			}else if(item.mId == 5){
				if (item.isShow) {
					((TextView)findViewById(R.id.posm_errorinfo_label)).setText(item.mName);
				} else {
					findViewById(R.id.posm_5).setVisibility(View.GONE);
				}
			}
		}else if(item.mType == StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP){
			if (item.mId == 1) {
				if (item.isShow) {
					mBackup1Title.setText(item.mName);
				} else {
					findViewById(R.id.posm_backup1_layout).setVisibility(View.GONE);
				}
			} else if (item.mId == 2) {
				if (item.isShow) {
					mBackup2Title.setText(item.mName);
				} else {
					findViewById(R.id.posm_backup2_layout).setVisibility(View.GONE);
				}
			}
		}
	}

	/**
	 * 从管理员查询结果数据更新界面
	 */
	private void setDataFromAdminSearchData(){
		findViewById(R.id.svbottom_split_menu).setVisibility(View.GONE);
		findViewById(R.id.svbottom_menu_save).setVisibility(View.GONE);
		if (DataUtils.mQueryVisitContentResult.Data != null) {
			List<ProjectDataItem> list = DataUtils
					.getProjectDataList(StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSM,
							StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_POSMBACKUP);
			if (list != null && list.size() > 0) {
				for (ProjectDataItem item : list) {
					updateViewFromProject(item);
				}
			}
			int iPCorner = getStringIndex(DataUtils.mQueryVisitContentResult.Data.SampleCornerPost);
			if(iPCorner != -1){
    		    mPCornerRadioGroup.check(mPCornerRadioGroup.getChildAt(iPCorner).getId());    
            }
			ViewsUtil.setRadioGroupdisable(mPCornerRadioGroup);
			int iPoster = getStringIndex(DataUtils.mQueryVisitContentResult.Data.PosterHang);
    		if(iPoster != -1){
    		    mPosterRadioGroup.check(mPosterRadioGroup.getChildAt(iPoster).getId());    
            }
    		ViewsUtil.setRadioGroupdisable(mPosterRadioGroup);
    		int iSinglePage = getStringIndex(DataUtils.mQueryVisitContentResult.Data.SinglePage);
    		if(iSinglePage != -1){
    		    mSinglepageRadioGroup.check(mSinglepageRadioGroup.getChildAt(iSinglePage).getId());    
            }
    		ViewsUtil.setRadioGroupdisable(mSinglepageRadioGroup);
    		int iIstand = getStringIndex(DataUtils.mQueryVisitContentResult.Data.StandPileHead);
    		if(iIstand != -1){
    		    mIstandRadioGroup.check(mIstandRadioGroup.getChildAt(iIstand).getId());    
            }
    		ViewsUtil.setRadioGroupdisable(mIstandRadioGroup);
    		mErrorInfoView.setText(DataUtils.mQueryVisitContentResult.Data.ExceptionDetails);
    		mErrorInfoView.setEnabled(false);
    		mBackup1Title.setVisibility(View.GONE);
    		mBackup1View.setVisibility(View.GONE);
    		mBackup2Title.setVisibility(View.GONE);
    		mBackup2View.setVisibility(View.GONE);
    		if(DataUtils.mQueryVisitContentResult.Data.PosmBackups != null){
    			int index = 0;
    			for(SyncModel.DataVisitContentSpecial content : DataUtils.mQueryVisitContentResult.Data.PosmBackups){
    				if(index == 0){
    					mBackup1Title.setText(content.Title);
    					mBackup1View.setText(content.Value);
    					mBackup1Title.setVisibility(View.VISIBLE);
    		    		mBackup1View.setVisibility(View.VISIBLE);
    				}else{
    					mBackup2Title.setVisibility(View.VISIBLE);
    					mBackup2View.setVisibility(View.VISIBLE);
    					mBackup2Title.setText(content.Title);
    					mBackup2View.setText(content.Value);
    				}
    				index++;
    			}
    		}
    		mBackup1View.setEnabled(false);
    		mBackup2View.setEnabled(false);
		}
	}

	/**
	 * 获取齐 缺index
	 */
	private int getStringIndex(String status){
		if(status != null){
			if(getString(R.string.posm_status_1).equals(status)){
				return 0;
			}else if(getString(R.string.posm_status_2).equals(status)){
				return 1;
			}else if(getString(R.string.posm_status_3).equals(status)){
				return 2;
			}else if(getString(R.string.posm_status_4).equals(status)){
				return 3;
			}	
		}
		return -1;
	}

	/**
     * 退出提示
     * 
     */
    private void popExitDialog() {
       Actions.popExitDialog(this);
    }
}
